{{ extend '../_layouts/home.html' }}

{{ block 'title' }}{{ '多人博客 - 新增话题' }}{{ /block }}

{{ block 'body' }} 
<section class="container">
    <div class="col-md-9 bgColor">
        <ul class="breadcrumb">
            <li><a href="/">主页</a></li>
            <li class="active">发布话题</li>
        </ul>
        <form action="" id="post_topic">
            <input type="hidden" name="uId" value="{{ user._id }}">
            <div class="form-group">
                <label for="exampleInputPassword1">选择板块</label>
                <select class="form-control" name="type">
                    <option value="">请选择</option>
                    <option value="分享">分享</option>
                    <option value="问答">问答</option>
                    <option value="招聘">招聘</option>
                    <option value="测试">测试</option>
                </select>
            </div>
            <div class="form-group">
                <label for="title">标题</label>
                <input type="text" class="form-control" id="title" placeholder="请输入标题" name="title">
            </div>
            <div class="form-group">
                <div id="editor">
                    <textarea style="display:none;" name="content"></textarea>
                </div>
            </div>
            <button type="submit" class="btn btn-success">提交</button>
        </form>
    </div>
    <div class="col-md-3">
        <div class="bg2Color">
            <ul class="breadcrumb">
                <li class="active">Markdown 语法参考</li>
            </ul>
            <a href="https://segmentfault.com/markdown">Markdown 文档</a>
        </div>
    </div>
</section>
{{ /block }}
{{ block 'script' }}
<script type="text/javascript">
    $(function() {
        var editor = editormd("editor", {
            width: "100%",
            height: "500px",
            path : "/node_modules/editor.md/lib/",
            watch: false,
            placeholder: "请输入您想说的吧！",
            emoji: true
        })
        $('#post_topic').on('submit', function (e) {
            e.preventDefault()
            var formData = $(this).serialize()
            $.ajax({
                url: '/topic/new',
                type: 'post',
                data: formData,
                dataType: 'json',
                success: function (data) {
                    var err_code = data.err_code
                    if (err_code === 0) {
                        window.location.href = '/'
                    }
                }
            })
        })
    })
</script>
{{ /block }}